package com.x52im.rainbowchat.http.logic;

import com.alibaba.fastjson.JSON;
import com.eva.framework.Processor;
import com.eva.framework.dto.SysActionConst;
import com.eva.framework.utils.EndsExceptionFactory;
import com.x52im.rainbowchat.http.logic.dto.AlipayCashDTO;
import com.x52im.rainbowchat.http.logic.dto.AlipayDepositDTO;
import com.x52im.rainbowchat.http.logic.pay.alipay.MCash;
import com.x52im.rainbowchat.http.logic.pay.alipay.MDeposit;
import com.x52im.rainbowchat.http.logic.pay.alipay.MPayPsw;
import com.x52im.rainbowchat.http.logic.pay.alipay.MQuery;

public class AlipayProcessor implements SysActionConst, Processor {

    @Override
    public Object process(int job_dispatch_id, int action_id, Object _newData, Object oldData, User user) throws Exception {
        Object ret = null;
        String newDataJSON = (String) _newData;
        switch (job_dispatch_id) {
            case 11:// 充值 获取唤起支付宝客户端的str
                AlipayDepositDTO dto = JSON.parseObject(newDataJSON, AlipayDepositDTO.class);
                dto.setUserUid(Integer.parseInt(user.getUserUid()));
                ret = new MDeposit().getOrderStr(dto);
                break;
            case 12:// 充值 获取用户支付成功后的同步通知参数
                AlipayDepositDTO dto1 = JSON.parseObject(newDataJSON, AlipayDepositDTO.class);
                dto1.setUserUid(Integer.parseInt(user.getUserUid()));
                ret = new MDeposit().getAliOrderInfo(dto1);
                break;
            case 20:// 查询充值或者提现的结果
                ret = new MQuery().queryDepositResult(newDataJSON);
                break;
            case 30:// 提现
                AlipayCashDTO dto2 = JSON.parseObject(newDataJSON, AlipayCashDTO.class);
                ret = new MCash().transfer(dto2);
                break;
            case 40:// 验证支付密码
                ret = new MPayPsw().check(newDataJSON);
                break;
            default:
                throw EndsExceptionFactory.INVALID_JOB_DISPATCHER_ID(job_dispatch_id);
        }
        return ret;
    }
}
